public class test13 {
    public int maxValue (int[][] grid) {
        // write code here
        if(grid == null || grid.length==0)
            return 0;

        int rows = grid.length; //行
        int cols = grid[0].length; // 列

        for(int j = 1;j<cols;j++)
            grid[0][j] += grid[0][j-1]; //只能从左边到达

        for(int i=1;i<rows;i++){
            for(int j=1;j<cols;j++)
                grid[i][j] += Math.max(grid[i-1][j],grid[i][j-1]);
        }

        return grid[rows-1][cols-1];
    }
}
